package leecode

func productExceptSelf(nums []int) (result []int) {
	rightArr := make([]int, len(nums))
	leftArr := make([]int, len(nums))
	leftArr[0] = 1
	for i := 1; i < len(nums); i++ {
		leftArr[i] = nums[i-1] * leftArr[i-1]
	}
	rightArr[len(nums)-1] = 1
	for i := len(nums) - 2; i >= 0; i-- {
		rightArr[i] = nums[i+1] * rightArr[i+1]
	}
	for i := 0; i < len(nums); i++ {
		result = append(result, leftArr[i]*rightArr[i])
	}
	return
}
